<?php

declare(strict_types=1);

namespace Core\Monolog\Handler;

use Monolog\Level;
use Monolog\LogRecord;

/**
 * 流日志 - 处理器.
 *
 * 复写：isHandling()
 *
 * @see https://hyperf.wiki/3.1/#/zh-cn/logger
 * @todo 待优化判断写法
 */
class StreamHandler extends \Monolog\Handler\StreamHandler
{
    /**
     * 是否 - 处理日志.
     *
     * 说明：重写该方法，使得 [info、waring、notice] [debug] [error] 级别日志单独存储
     */
    public function isHandling(LogRecord $record): bool
    {
        return match ($record->level->value) {
            Level::Debug->value => $record->level->value == $this->level->value,
            $record->level->value >= Level::Error->value => $this->level->value >= Level::Error->value && $this->level->value <= Level::Emergency->value,
            default => $this->level->value >= Level::Info->value && $this->level->value <= Level::Warning->value,
        };
    }
}
